package homework;


import org.junit.Test;

import java.util.Arrays;
import java.util.Random;

public class Player {



    public Card[] newCards() {
        Card[] cards=new Card[54];
        int index=0;
        for(int rank=Card.RANK_3 ;rank<=Card.RANK_2;rank++){
            for(int suit=Card.SUIT_HEITAO;suit<=Card.SUIT_FANGKUAI;suit++){
                cards[index++]=new Card(suit, rank);
            }
        }
        cards[index++]=new Card(Card.SUIT_NULL, Card.RANK_joker);
        cards[index++]=new Card(Card.SUIT_NULL, Card.RANK_joker_2);
        Random r=new Random();
        for(int i=0;i<cards.length-1;i++){
            int j=r.nextInt(i);
            Card temp=cards[i];
            cards[i]=cards[j];
            cards[j]=temp;
        }
        return cards;
   }
    private String name;
    private Card[] cards;

    public Player(String name) {
        this.name = name;
        cards = new Card[0];
    }

    @Override
    public String toString() {
        return "Player{" +
                "name='" + name + '\'' +
                ", cards=" + Arrays.toString(cards) +
                '}';
    }
    public void addCard(Card card){
        //先扩容
        this.cards = Arrays.copyOf(cards, cards.length+1);
        this.cards[this.cards.length-1]=card;

    }

    public String getName() {
        return name;
    }

    public Card[] getCards() {
        return cards;
    }
}



